#include "types.h"
#include "stat.h"
#include "user.h"


void
foo(void)
{
		double l;
		int k;
        int j;
        l=0;
        for (j=0; j<1000; j++)
        {
                printf(1,"child %d prints for the %d time\n",getpid(),j);
        	/*for (k=0; k<99999; k++)
        		l = k/100000;*/
        }
}

void 
RRsanity(void)
{

        int i,k,t,pid,cpid,wTime,rTime,tTime;
        int ans[10][3];
        for (i=0; i<10; i++)
        {
                pid=fork();
                if (pid == 0)
                {
                        foo();
                        exit();
                }
        }
        for (k=0; k<10; k++)
        {
                cpid=wait2(&wTime,&rTime);      
                ans[k][0] = cpid;
                ans[k][1] = wTime;
                ans[k][2] = rTime;      
        }
        printf(1,"\n\nfinal results:\n");
        for (t=0; t<10; t++)
        {
                tTime = ans[t][1]+ans[t][2];
                printf(1,"child %d stats: waiting-time = %d running-time = %d turnaround-time = %d\n",ans[t][0],ans[t]  [1],ans[t][2],tTime);
        }
}

int
main(void)
{
        RRsanity();
        exit();
}
